<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>while课堂案例</title>
    <script>
        //1.打印人的一生,从1岁到100岁
        var age = 0;
        var i = 1;
        while (i <= 100) {
            console.log(i + '岁了');
            i++;
        }
        //2.计算1~100之间所有整数的和
        var a = 1;
        var sum = 0;
        while (a <= 100) {
            sum += a;
            a++;
        }
        console.log(sum);
        //3.弹出一个提示框,你爱我吗?如果输入我爱你,就提示结束,否则,一直询问.
        var message = prompt('你爱我吗?');
        while (message !== '我爱你') {
            message = prompt('你爱我吗?');
        }
        alert('我也爱你啊!');


        //自己动手丰衣足食
        /*  var a = prompt('你爱我吗'); //说明while可以做更复杂的条件判断
         while (a != '我爱你') {
             var b = prompt('你爱我吗????');
             if (b == '我爱你') {
                 alert('好哦');
                 break;
             }
         }
         alert('好哦'); */
    </script>
</head>

<body>

</body>

</html>